package com.situ.ssm.controller;

import java.util.Arrays;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.ssm.common.ServerResponse;
import com.situ.ssm.entity.Student;
import com.situ.ssm.service.IStudentService;

@Controller
@RequestMapping("/student")
public class StudentController {
	
//	@InitBinder
//	public void initBinder(WebDataBinder binder) {
//		// 把字符创的日期类型转换成Date类型
//		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//		simpleDateFormat.setLenient(false);
//		binder.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));
//	}
	
	@Autowired
	private IStudentService studentService;
	
	@RequestMapping("/getStudentListPage")
	public String getStudentListPage() {
		return "student_list";
	}
	
	// /student/pageList.action?page=1&limit=30
	@RequestMapping("/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page, Integer limit, Student student) {
		return studentService.pageList(page, limit, student);
	}
	
	@RequestMapping("/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return studentService.deleteById(id);
	}
	
	@RequestMapping("/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(Integer[] ids) {
		// ids: 40,41
		System.out.println(Arrays.toString(ids));// [40, 41]
		return studentService.deleteAll(ids);
	}
	
	@RequestMapping("/getInsertPage")
	public String getInsertPage() {
		return "student_insert";
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public ServerResponse insert(Student student) {
		System.out.println(student);
		return studentService.insert(student);
	}
	
	@RequestMapping("/getUpdatePage")
	public String getUpdatePage(Integer id, Model model) {
		
		return "student_update";
	}
}
